Automation Software
Command-Line Utilities
wrap lines to a maximum width of 80 in FILE
fold -w 80 -s FILE
Hammerspoon
add stuff: open config, type in LaTeX, save, reload config
bind function to hotkey
hs.hotkey.bind({"functionKey", …}, "key",…, function()
…
end)
functionKey: cmd alt ctrl
key: X \\ Left
the {} must stay even if it`s empty
show alert message
hs.alert.show("message")
generate system notification with title and content
hs.notify.new({title="title", informativeText="content"}):send()
define the current window as win
local win = hs.window.focusedWindow()
define win’s window frame as f
local f = win:frame()
position of f is (f.x, f.y)
its width and height f.w, f.h
define the screen win at as screen
local screen = win:screen()
define screen's screen frame as max
local max = screen:frame()
update the frame of win as f
win:setFrame(f)
hs.pathwatcher.new(.....):start()
reload config
hs.reload()
automatically reload config
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == ".lua" then
doReload = true
end
end
if doReload then
hs.reload()
end
end
myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
hs.alert.show("Config loaded")
get the home direction of the system
os.getenv("HOME")
connect string to path
..
call function whenever changes in direction
hs.pathwatcher.new("direction", function):start()
Computer Science
Discrete Mathematics for Computer Science
proof by induction
steps with example
- variable
- property
- base case
- induction hypothesis
- weak induction
assume is true - strong induction
assume is true
- weak induction
- induction step
induction hypothesis is true
- Machine Learning
- polynomial data fitting
- k-nearest neighbors predictor
- gradient descent
- logistic-regression classifier
- support vector machine (SVM)
Machine Learning
general problem format
given input , want output
- traditional approach
hand-craft the function - machine learning
build another function and use it to generate an approximation
machine learning is about building a function
- training data
- class of allowed function
use a predefined algorithm to compute with the goal:
simplification using feature vector
convert input into a 1d vector, making machine learning generally applicable
- feature vector
- training set
- hypothesis space
predefined algorithm produce so that
loss
estimation of the error of
zero-one loss
quadratic loss
empirical risk
average lost based on the training set
three types of machine learning problems
classification problem
label given data
- classifier (predictor) : the produced function
all possible training set
signature of machine learning function
- learn (or train) classifier from training set
- inference: apply classifier on any data
- testing: apply classifier on unseen data
classifier define a partition of
regression problem
given data, return a vector
clustering problem
group given data
supervised/ unsupervised machine learning
supervised learning: classification, regression
unsupervised learning: clustering
polynomial data fitting
not machine learning but similar
- number of monomial
interpolation in polynomial data fitting
achieve loss
- always interpolate
- overfitting
k-nearest neighbors predictor
remember the whole training set
return average of s corresponding to the closest s to
- useful for both classification and regression
- smaller results in worse overfitting
- good interpolation and poor extrapolation
Voronoi diagram

gradient descent
stochastic gradient descent (SGD)
group training set randomly into mini-batch, use gradient from each mini-batch to descent
- mini-step are in the right direction on average
- epoch: using all data once
step size
-
fixed
-
decreasing
-
momentum
-
line search
subgradient
logistic-regression classifier
- score-based
score function for linear boundary
signed distance to hyperplane
hyperplane
-
is perpendicular to
-
distance of from origin
-
signed distance of from
logistic function
![]()
then the score function is
- activation is signed distance scaled
softmax function
softmax function in activation
cross entropy loss for binary classification
cross entropy loss of assigning score to point whose true label is
- differentiable so we can do gradient descent
- base of does not matter
- resulting risk function is weakly convex
cross entropy loss for -class case
- true label
- prediction
- one hot encoding of
support vector machine (SVM)
binary support vector machine
separating hyperplane for binary support vector machine
-
decision rule
-
margin for with parameter
-
margin of training set
-
linearly separable if
-
hinge loss
reference margin
where
- separating hyperplane
empirical risk of binary support vector machine
- bigger smaller
soft linear support vector machine
subgradient of hinge function
support vector machine with kernel
representer theorem
loss function in the form
where increasing, ,
s.t.
-
proof: by writing
and proving by contradiction
support vector
sample that are misclassified or classified correctly with a margin not larger than
only support vector contribute to
kernel for support vector machine
where kernel
for some
is a kernel of
-
where
-
Mercer's condition: s.t.
is finite,
-
Gaussian kernel
- radial basis function (RBF) SVM
Data Science
Visualization
data type
item
discrete entry
attribute
measured property
attribute type
-
nominal (categorical)
with equality relationship
-
ordinal
with order
-
quantitative (numerical)
with algebra
- ratio: with meaningful
- interval
link
relationship between item
position
spatial location
grid
sampling strategy for continuous data
structured data
- table: item & attribute
- flat
- multi-dimensional
- network: item & attribute & link
- field: grid & attribute
- geometry: position
unstructured data
text, audio, graphics…
symbolic display
- parallel coordinate
- treemap
- field
- choropleth map
- star plot
graph
- framework
- scale
- content
- mark
- label
- title
- axis
mark
represent item, link
- point
- line
- area
channel
represent attribute
- position
- color
- hue
- saturation
- luminance
- shape
- glyph
- tilt
- size
- area
- texture
characteristic of channel
- selective
- associative
- quantitative
- order
- length
analysis framework
four level
- domain situation
- data/task abstraction
- visual encoding/interaction idiom
- algorithm
three question
- what
- why
- how
user task
- query
- retrieve value
- find extremum
- determine range
- search
- sort
- filter
- consume
- compute derived value
- characterize distribution
- find anomaly
- cluster
- correlate
graph theory
- independent set: no edge
- clique: all possible edge
- path: all edge can be consecutively traversed
- tree: no cycle
- network
- unconnected graph
- biconnected graph: no articulation point
- articulation point: break the graph if deleted
- bipartite graph: edge between only vertex for two set
centrality
quantity to measure vertex importance
degree of vertex
number of connected node
- in-degree/ out degree for directed graph
betweeness of vertex
sum of number of shortest path through the vertex divided by number of shortest path between each pair of vertex
closeness of vertex
sum of geodesic distance between the vertex and every other
geodesic distance between vertex
number of edge between them on the shortest path
eigenvector of vertex
adjacency matrix dot vector of degree
clustering coefficient
Documentation
Pandoc
How to use Pandoc to produce a research paper
create paper.pdf from paper.md and paper.bib
pandoc --citeproc --bibliography=paper.bib --variable classoption=twocolumn --variable papersize=a4paper -s paper.md -o paper.pdf
macOS
Sucklessfy
allow apps from anywhere
sudo spctl --master-disable
DS.Store
remove all .DS_Store in subfolder
find . -name '.DS_Store' -type f -delete
Mathematics
- Abstract Algebra
- integer
- relation
- group
- ring
Abstract Algebra
integer
natural number
well-ordering axiom
s.t.
division algorithm
, s.t.
divisibility
, or divide , s.t.
- , or do not divide
greatest common divisor
, s.t.
or
Euclidean algorithm
-
let
-
apply division algorithm on until
-
Bézout's identity
s.t.
- find : substitute from the last equation in Euclidean algorithm up
relatively prime
are relatively prime
prime number
, then is prime , the only divisor of are
- composite number: not prime
Euclid's lemma
prime, or
- , then prime if , then or
- prime,
fundamental theorem of arithmetic
can be factored uniquely into product of primes
relation
relation on is a subset
or is related to
- or is not related to
partition of set
is a non-empty set, partition of
s.t.
- is equivalence relation
equivalence relation
- reflexive:
- symmetric:
- transitive:
equivalence class
equivalence class of representative
-
-
are either disjoint or identical
-
quotient set of by
is partition of
modular arithmetic
, then
or (mod ) or is congruent to modulo
congruence module
( mod ) or quotient set of by
- is equivalence relation on
congruence class
equivalence class of modulo
- there are distinct congruence classes
addition and multiplication in modular arithmetic
- addition and multiplication are well-defined
- additive inverse
- either has unique multiplicative inverse or it has not
unit
- is unit
zero divisor
-
, then
is prime
, is unit
or , or no zero divisor
group
ordered pair
- set
- binary operation
axiom group satisfy:
- is associative
- identity:
- inverse:
property
- is unique
- , has unique inverse
- and has unique solution, cancellation law work
- value of is independent of the bracketing
abelian group (commutative group)
is commutative
- under
- under
nonabelian group
- dihedral group of order ,
general linear group of degree over
special linear group of degree over
binary operation
associative binary operation
commutative binary operation
order of group
, or order of , is the number of distinct elements in
order of element in group
, or order of , is the smallest s.t.
or if DNE
- are distinct
Torsion group
is a Torsion group, then is finite
-
Torsion-free group:
-
Torsion subgroup of : for abelian group ,
-
-
is abelian Torsion group, then has largest order
dihedral group
rotation () and reflection () of n-gon
- order
- degree
permutation of set
permutation of : bijection
symmetric group on set
set
, the set of permutation of
, symmetric group on
- , symmetric group of degree
- nonabelian
array notation of permutation
is permutation on
cycle notation of permutation
cyclically permute and fix the rest
- -cycle (or cycle of length )
transposition
-cycle
- can be expressed as product of transposition
- not unique
- even permutation: length of such transposition is even
- odd permutation
disjoint cycle
no common number
- disjoint
- can be uniquely expressed as product of disjoint cycle of length at least 2
subgroup
, or is a subgroup of
- , or is a proper subgroup of
subgroup test
centralizer of group
- if
center of group
normalizer of group
where
for group and subset
- abelian
cyclic group
- generator
- cyclic group are abelian
fundamental theorem of cyclic group
homomorphism
are group
well-defined map is homomorphism
property
- monomorphism: injective
- epimorphism: surjective
- , or isomorphism: bijective
well-defined map
is well-defined
automorphism
isomorphism from to
- inner automorphism of ,
isomorphism
property
- abelian abelian
- have same number of elements of order
- prime
equivalence relation from isomorphism
is set of groups
is equivalence relation on
cyclic isomorphism
Cayley's theorem
group , permutation , s.t.
kernel and image of homomorphism
is homomorphism
-
kernel of
- measure how much is not injective
- is injective
-
image of
- is injective
-
fiber of under
- is surjective
coset
,
-
left coset of in
- bijection between and
- or
-
right coset of in
- bijection between and
- or
-
is representative
- left and right coset are not necessarily equal
set of coset
-
set of left coset
-
set of right coset
- bijection between and
index of subgroup in group
index of in
is number of distinct left (right) coset
Lagrange's theorem
for finite
normal subgroup
, or is normal in
normal subgroup test
- if , then
quotient subgroup
is the quotient group of by
under operation :
natural projection
natural projection of onto
homomorphism
- is epimorphism
isomorphism theorem
first isomorphism theorem
homomorphism
-
under
second isomorphism theorem (diamond theorem)

third isomorphism theorem
-
-
under
-
forth isomorphism theorem
, natural projection
bijection
property of
ring
a triple s.t.
-
is abelian group
-
is associative
-
distributive
commutative ring
ring with identity
- is unique
division ring
is ring with identity and
field
commutative division ring
zero divisor of ring
is zero divisor
- is not zero divisor, or
integral domain
commutative ring
is integral domain no zero divisor:
- or
- is finite is field
unit of ring
is ring with identity,
is unit
- group of units of ,
- zero divisor cannot be unit
subring
is subring of
- is a subgroup of
- is closed under multiplication
relationship between identity
- , unit in are unit in
subring test
is subring of
is finite subring of
center of ring
is ring with
- is subring with
- is division ring is field
characteristic of ring
if s.t.
then , else
- is integral domain is or prime
- finite
nilpotent of commutative ring with identity
commutative ring with
is nilpotent
- is or zero divisor
- is nilpotent
- is unit
- unit is unit
polynomial ring
is commutative ring with identity, is indeterminate
ring of polynomial in with coefficient in
- commutative
- identity
- is subring of
- is subring of is subring of
- is integral domain,
- is integral domain
polynomial in with coefficient in
- degree
matrix ring
is ring,
matrix ring of degree over
- has identity
- is not commutative
- has zero divisor
- set of scalar matrix in is a subring
- is subring of is subring of
scalar matrix
ring homomorphism
are ring
well-defined map is ring homomorphism
- monomorphism, epimorphism, isomorphism, kernel, image
- is subring
- is subring
- they have the same property (commutative, identity, inverse)
ideal of ring
subring is ideal of
- proper ideal: proper subset that is ideal
ideal test
subset of ring
is ideal
maximal ideal
ideal of is maximal ideal
- is ideal of , or
- easily seen in lattice
- not necessarily exist
- every proper ideal is contained in a maximal ideal
- is commutative, is field
prime ideal
ideal of is prime ideal
- or
- is commutative,
- is prime ideal is integral domain
- is integral domain is prime ideal
- every maximal ideal is prime ideal
quotient ring
is ideal of
is quotient ring of by
-
-
commutative commutative
-
natural projection
isomorphism theorem for ring
first isomorphism theorem for ring
is ring homomorphism
- is ideal of
second isomorphism theorem for ring
are subring of , is ideal
- is subring of
- is ideal of
- is ideal of
third isomorphism theorem for ring
are ideal of ,
- is ideal of
forth isomorphism theorem for ring
is ideal of , natural projection
bijection
are subring of ,
- is ideal of is ideal of
Arithmetics
sigma notation
- linear
common sum
trigonometric transformation
greatest integer smaller or equal than
binomial coefficient
triangle inequality
reverse triangle inequality
power when
- Calculus
- function
- mathematical model
- limit
- derivative
- extremum
- indeterminate form
- antiderivative
- integral
Calculus
function
piecewise defined function
different formula for different part of domain
- step function
composite function
mathematical model
empirical model
model based entirely on data
limit
is defined on interval containing except possibly
-
limit exist iff limit from both side exist
limit law
-
linear: sum law, difference law, constant multiplication law
-
product law, power law
-
quotient law
derivative rule
-
rational
- limit calculation technique
divide numerator and denominator by highest power of
- limit calculation technique
direct substitution property
polynomial limit can be pulled out
limit comparison
near
squeeze theorem (sandwich theorem)
near ,
e.g.
continuity
is continuous at
- continuous from the left/ right
- continuous on an interval continuous at every point in interval
- continuous function after operation in limit law are still continuous
- function continuous in domain
- polynomial
- rational
- (inverse) trigonometric
- exponential
- logarithmic
discontinuity
- removable
redefining at single point remove discontinuity - unremovable
- infinite discontinuity
- jump discontinuity
intermediate value theorem
continuous on ,
derivative
derivative of at
derivative function
differential operator ,
differentiability
is differentiable at
exist
is differentiable on interval
is differentiable at every point in the interval
- differentiable at continuous at
second derivative
derivative rule
-
linear: constant multiplication, sum, difference rule
-
definition of
-
product rule
-
quotient rule
-
chain rule
implicit differentiation
differentiate both side of equation
derivative of (inverse) trigonometric function
derivative of logarithmic function
logarithmic differentiation
take the logarithm of both side of equation and differentiate
differential
hyperbolic function
- hyperbolic identity similar to trigonometric identity
- inverse hyperbolic function composed of logarithm
- derivative of hyperbolic function compose of hyperbolic functions
- derivative of inverse hyperbolic function have similar form like that of trigonometric function
extremum
extreme value theorem
continuous on closed interval
has absolute maximum and absolute minimum in the interval
Fermat's theorem
has extremum at , exist
critical number
or DNE
closed interval method
find absolute extremum of continuous function on closed interval by checking the value of the critical number and endpoint
mean value theorem
continuous on , differentiable on
Rolle's theorem
continuous on , differentiable on ,
derivative test
first derivative test
- increasing/ decreasing
- extremum
second derivative test
concave upward/ downward
graph of lie above/ below all its tangent
inflection point
indeterminate form
form that can transform to indeterminate form
L'Hospital's rule
differentiable, near (excluding ),
is in indeterminate form
antiderivative
- are also antiderivative of
integral
definite integral
-
integrable
-
integral sign
-
integrand
-
limit of integration
- lower limit
- upper limit
-
Riemann sum
midpoint rule
choose to be the midpoint
property of definite integral
- linear
fundamental theorem of calculus
continuous on
continuous on and differentiable on
is any antiderivative of
indefinite integral
mean
net change theorem
substitution rule
chain rule
trigonometric integral and trigonometric substitution
from
from
rational function integral
symmetric integral
volume from integral
from to , rotate and about -axis, volume:
from to , rotate and about -axis, volume:
arc length from integral
surface area from integral
from to , rotate about -axis, surface area:
average of function
mean value theorem for integral
continuous
integration by part
power rule
improper integral
integral with infinite interval
- continuous on
- exist
- opposite for
- convergent if limit exist
- divergent if limit DNE
- both side exist is their sum
discontinuous integral
- continuous on , discontinuous at
- exist
- opposite for when continuous on , discontinuous at
- convergent if limit exist
- divergent if limit DNE
- both side exist can connect them
improper integral comparison
, converge
converge
- Differential Equation
- first order equation
- below old class note
- ordinary differential equation ODE
- one-dimensional (smooth) dynamical system
- discrete dynamical system
- second-order linear equation
- higher order differential equation
- autonomous planar system of differential equation
- non-autonomous planar system
- chaos
- linear system
- matrix exponential
- planar linear system
- almost linear system
- energy method
- Lyapunov's Method
- non-constant periodic solution
- bifurcation in one-dimensional system
- bifurcation in planar system
Differential Equation
an equation that contains an unknown function and one or more of its derivatives.
- order
highest derivative - solution
function that satisfy the equation - initial condition
- initial value problem
direction field
sketch lines as a grid with direction from derivative from the equation
Euler's method
- step size
first order equation
separable equation
below old class note
ordinary differential equation ODE
- general form
order of differential equation
the order of the highest order derivative
solution
any function that satisfy the equation
general solution
collection of all solution
initial value problem
- initial condition
use the general solution and the initial condition
direction field
solving first-order differential equation
numerical approximation
- Euler's method example code
f[x0_, y0_] := x0 y0
step[{x0_, y0_}] := {x0 + 0.01, y0 + 0.01 f[x0, y0]}
{x100, y100} = Nest[step, {1, 1}, 100]
separable equation
use separation of variable
- consider
- integrate both side
- explicit solution
- implicit solution relationship between variable
linear equation
where are continuous,
standard form
multiply both side to construct chain rule form where is the integration factor
substitution
Bernoulli equation
solution
substitution reduce the Bernoulli equation to linear equation
Ricatti equation
solution
- one solution
- substitution reduce the Ricatti equation to linear equation
existence and uniqueness theorem
is continuous on and satisfy Lipschitz condition
Lipschitz condition
metric space
- denote distance
- can be defined using
limit
sequence converge to limit in
- the limit is unique
Cauchy sequence
complete metric space
every Cauchy sequence converge to some point in
fixed point
point stand for function for operator
initial value problem integral form
for let operator : then is a fixed point for operator
Banach fixed point theorem
is complete metric space is a contraction has a unique fixed point in
- contraction is a contraction if
Picard iteration
sequence where with
one-dimensional (smooth) dynamical system
continuously differentiable function
- flow of dynamic system
autonomous equation
assume satisfy condition of existence and uniqueness theorem
time-shift immunity
if the solution of is then the solution of is
equilibrium
,
- asymptotically stable move towards from both side
- unstable move away from from both side
phase line
draw the sign graph of
linearization (approximate linear dynamic)
let
- blow up and unstable
- shrink down and asymptotically stable
- cannot linearize, need higher order
differential equation to dynamical system
where
dynamical system to differential equation
and convert to initial value problem with autonomous equation
discrete dynamical system
map
invertible
fixed point
not change when apply
stability
linearization
- dynamics
- unstable
- asymptotically stable
Poincaré map
time-periodic non-autonomous system
where
periodic time-shift immunity
if the solution of is then the solution of is
Poincaré map for the system
define function : , let be the solution to
periodic solution
fixed point of Poincaré map
stability
- asymptotically stable
- unstable
example code
P[h_,x0_] := NDSolveValue[
x'[t] == x[t](1-x[t]) - h x[t] Sin[t] && x[0] == x0,
x[2 Pi], {t, 0, 2 Pi}]
second-order linear equation
second-order homogeneous linear equation with constant coefficient
solution
a linear combination of two solution where is not constant (linearly independent)
auxiliary equation
under the hood: try
- two distinct real root
- double real root two solution
- two complex root
- alternatively where
- alternatively: real-valued solution
- complex-valued solution
second-order non-homogeneous linear equation
solution
- let then satisfy
- find one particular solution therefore
linear differential operator
given ,
linear operator
apply operator on function linear
find a particular solution
polynomial
use the degree of as the degree of the particular solution
exponential
where is polynomial same as the polynomial method but multiply the same exponential
- when is one root of auxiliary equation, multiply the polynomial solution by
- when is double root of auxiliary equation, multiply the polynomial solution by
trigonometric
same as polynomial but degree needs to be the maximum between and need two polynomial
- when is one root of auxiliary equation, multiply the polynomial solution by
combination of above case
split to that match above case
higher order differential equation
-th order where are continuous on
existence and uniqueness
above equation with has unique solution are continuous,
system in matrix form
Wronskian
determinant
linear dependency and Wronskian
linearly independent in
- linearly dependent function linearly dependent in
homogeneous linear equation with constant coefficient
auxiliary equation
complex root counting multiplicity
general solution
linear combination of solution time repeatedly if a solution has multiplicity or more
autonomous planar system of differential equation
with respect to
initial value problem
- autonomous can start wherever wanted, let
integral curve
parameterized curve of
velocity vector
phase plane
-plane
- phase space higher dimension
phase portrait
phase plane with several solution
equilibrium
- equilibrium solution
solution
- convert to differential equation with one variable
- conserved quantity / integral of motion
- reduce to non-autonomous first order equation
non-autonomous planar system
where are periodic in with period
periodic time-shift immunity
similar to periodic time-shift immunity in one dimension if is solution to then is solution to
Poincaré map for non-autonomous periodic dynamical system
- also known as stroboscopic map
example: mass on spring with external forcing
forced duffing equation
period
Poincaré map for forced duffing equation
P[b_,F_,γ_][{x0_, y0_}]:=
NDSolveValue[
x'[t]==y[t]&&y'[t]==-by[t]+x[t]-x[t]^3+F Sin[γ t]&&x[0]==x0&&y[0]==y0,
{x[2Pi/γ],y[2Pi/γ]},
{t,0,2Pi/γ}
]
chaos
sensitive dependence on initial condition
- two initial condition close to each other deviate exponentially fast
- the exact state of the system is fundamentally unpredictable though the system is deterministic
- chaotic attractor of the two initial condition look identical
Poincaré map for autonomous system
Henon-Heiles system
- conserved quantity
- hyperplane on consider an initial condition on corresponding to value for , when the solution reach again still conserve it is enough to know to know the rest define Poincaré map for
poincareMap[h_][{x0_,y0_}]:=Module[{stopTime},
NDSolveValue[
x1'[t]==y1[t]
&&y1'[t]==-x1[t]-2x1[t] x2[t]
&&x2'[t]==y2[t]
&&y2'[t]==-x1[t]^2-x2[t]+2[t]^2
&&x1[0]==0
&&y1[0]=Sqrt[2h-y0^2-x0^2+2/3 x0^3]
&&x2[0]=x0
&&y2[0]=y0
&&WhenEvent[x1[t]==0&&y1[t]>0,stopTime=t;"StopIntegration"],
{x2[stopTime],y2[stopTime]},
{t,0,Infinity}
]
]
linear system
planar linear system
where continuous
homogeneity
- homogeneous
- otherwise non-homogeneous
convert linear differential equation to linear system
linear differential equation define get a linear system
existence and uniqueness
If , are continuous functions in an interval and then for any initial vector there exists a unique solution of in that satisfies the initial condition .
linearity
linear combination of solution are also solution
linear dependency
linearly dependent vector
Wronskian
for solution
linear dependency and Wronskian
- solution are linearly dependent in
fundamental solution
collection of linearly independent solution
fundamental matrix
corresponding matrix
- invertible
- general solution for the linear system
- solution for the initial value problem with
- that is another fundamental matrix
- is a fundamental matrix
- let , then
linear system with constant coefficient
where is constant
find a solution
where satisfy
eigenvalue problem
is the solution to eigenvalue equation is non-zero eigenvector corresponding to is a root of characteristic polynomial
- is a complex eigenvalue is eigenvalue
- is eigenvector corresponding to is eigenvector corresponding to
linearly independent eigenvector and general solution
has linearly independent eigenvector corresponding to real eigenvalue general solution for is
real distinct eigenvalue
are real distinct eigenvalue of corresponding eigenvector are linearly independent a fundamental matrix is
complex eigenvalue
eigenvalue with eigenvector eigenvalue with eigenvector solution
matrix exponential
property
- , series converge
-
- trace of
diagonal matrix
diagonal matrix
matrix exponential and linear system
unique solution to the initial value problem with is
- derivative
exponential matrix as fundamental matrix
linear system has fundamental matrix
generalized eigenvector
a non-zero vector generalized eigenvector of associated with ,
- generalized eigenvector are also standard eigenvector
- is eigenvalue of with eigenvector
generalized eigenvector given characteristic polynomial
has characteristic polynomial linearly independent generalized eigenvector
compute
- find generalized eigenvector
- compute solution for
- fundamental matrix
planar linear system
where
characteristic polynomial

real distinct eigenvalue
- real eigenvalue
transformation
define by
- case 1a. (or )
all arrow point away from origin
- unstable node
- case 1b. (or )
all arrow point towards origin
- stable node
- case 1c. (or )
all arrow point towards origin on -axis, point away from origin on -axis
- saddle
- case 1d. (or ) all arrow point away from -axis parallel to -axis
- case 1e. (or ) all arrow point towards -axis parallel to -axis
complex conjugate eigenvalue
conjugate eigenvalue with corresponding eigenvector where
- complex eigenvalue
polar coordinate transformation
- case 2a. (or )
arrow rotate around origin moving away
- unstable spiral
- case 2b. (or )
arrow rotate around origin moving towards
- stable spiral
- case 2c. (or )
solution are closed curve with period
- center
rotation direction
- rotation direction on -plane
- , clockwise
- rotation direction on -plane
- same direction as on -plane
real repeated eigenvalue
generated eigenvalue of
- real eigenvalue
- case c1. (or both and are eigenvalue of )
all arrow point away from origin
- unstable node
- case c2. (or only is eigenvalue of )
all arrow point away from origin
- turn to the right with
- turn to the left with
- unstable
almost linear system
- almost linear system at
- is an equilibrium of
- is an almost linear system at the origin where
- almost linear system at the origin
- is an equilibrium of
- is continuous around
- are continuous near
- jacobian of
planar system
equilibrium
point
stability
- stable in English, given a bigger disk, one can always find a smaller disk, so that if you start from the smaller disk, you don't go out of the bigger disk
- asymptotically stable stable and
- unstable not stable
open disk
linearization theorem (Hartman-Grobman theorem)
transform the dynamics of system to the dynamics of system where
- system is almost linear at
- is hyperbolic
- coordinate transformation near ,
hyperbolic linear system
hyperbolic matrix
all eigenvalue have non-zero real part
hyperbolic equilibrium
equilibrium of is hyperbolic matrix
energy method
mechanical system
potential
antiderivative of
energy function
conserved quantity
level set
fix to
- graph of is only defined where
- the two parts above and below -axis mirror each other
- intersection with -axis are where
- curve is vertical at intersection
potential plane
-plane

equilibrium
linearization
are continuous near system is almost linear at equilibrium
- Jacobian corresponding to
- , minimum at linear system is a center linearization does not hold use Taylor series quadratic term level curve are approximate ellipse
- , maximum at linear system is a saddle by linearization theorem, level curve also saddle
Lyapunov's Method
isolated equilibrium
open disk of radius centered at does not contain other equilibrium
positive/ negative definite/ semidefinite function in
is open disk centered at is continuous in
- positive definite function in
- positive semidefinite function in
- negative definite function in
- negative semidefinite function in
- positive definite (/ semidefinite) function in negative definite (/ semidefinite) function in
directional derivative of along vector field (derivative of along the flow of )
planar system real-valued function
Lyapunov's stability theorem
planar system is an isolated equilibrium
- positive definite function in an open disk centered at
is negative definite in
is asymptotically stable
- explanation increase going away from origin decrease along vector field going away from origin will always go towards origin along vector field
- positive definite function in an open disk centered at is negative semidefinite in is stable
Lyapunov function
a function that satisfy the condition of either part of Lyapunov's stability theorem
Lyapunov's instability theorem
planar system is an isolated equilibrium
- continuous function in an open disk centered at
is positive definite in
open disk centered at ,
is unstable
- explanation increase along vector field going away from origin is higher somewhere than the origin will go away from origin at some point
- alternatively, instability for restrict system mean instability for whole system
non-constant periodic solution
limit cycle
closed curve
- planar system
- is a non-constant -periodic solution
- non-constant mean the periodic solution is not a single point
- at least one other solution ,
or
- distance
- explanation this solution go to the closed curve as time roll back or go forward
example of limit cycle
- coordinate transformation
- is constant for the specific
- dynamic in radial direction have equilibrium when
- stability can be determined using phase line
- each equilibrium correspond to a circular limit cycle
limit cycle enclose equilibrium
enclose at least one equilibrium
- enclose equilibrium the equilibrium cannot be saddle
Bendixson's negative criterion
- planar system
- simply connected domain
- have continuous partial derivative in
- does not change sign in
- system have no non-constant periodic orbit in
Poincaré-Bendixson Theorem
- planar system
- solution
- isolated region
- closed bounded
- solution stay in forever
- have continuous partial derivative in
- no equilibrium in
- is either periodic or approach a limit cycle in
bifurcation in one-dimensional system
is changing parameter
implicit function theorem
- smooth function
- , unique defined on ,
persistence of equilibrium
- is a smooth function
- , is an equilibrium when
- , unique smooth function defined on
- is equilibrium
fold bifurcation (saddle-node bifurcation)
smooth curve near
in English: curve of equilibria (bifurcation diagram) near look like parabola

condition
- is a smooth function
- , is an equilibrium when
- equilibrium do not persist
- transversality condition
- system undergo fold bifurcation at
stability
check
- stability depend on sign of , regardless of
- equilibrium is stable equilibrium is unstable
- equilibrium is unstable equilibrium is stable
proof
- , , implicit function theorem smooth function near ,
- define
- Evaluate at .
- Then we take the derivative of the relation with respect to . We find Evaluating at and using that we find Since and we can solve for to find
bifurcation in planar system
is the parameter
persistence of equilibrium
equilibrium persist where is equilibrium when
fold bifurcation (saddle-node bifurcation)
- supercritical bifurcation stable limit cycle + unstable spiral
- subcritical bifurcation unstable limit cycle + stable spiral
- Geometric Vector
- vector
- line
- plane
- cylinder
- vector function (vector-valued function)
Geometric Vector
vector
- displacement vector
- initial point
- terminal point
- zero vector
- unit vector
vector addition
- triangle law
- parallelogram law
scalar multiplication
component of vector
standard basis vector
dot product (scalar product, inner product)
angle between ,
perpendicular vector
direction angle
-
relation
-
conclusion
projection
cross product
- right hand rule determine direction of
magnitude of cross product
- equal to area of parallelogram by
parallel vector
property of cross product
- linear
triple product
scalar triple product
-
volume of parallelepiped by
-
coplanar
vector triple product
line
-
vector equation
-
parametric equation
where
-
symmetric equation
plane
-
vector equation
- normal vector
-
scalar equation
where
-
linear equation
plane-plane relation
- parallel plane
normal vector parallel - angle between plane
acute angle between normal vector
point-plane distance
cylinder
consist of parallel ruling through a plane curve
quadratic surface
second degree equation in three variable
standard form of quadratic surface
obtained after translation and rotation
or
- ellipsoid
all traces are ellipses - cone
horizontal traces are ellipses vertical traces in the planes and are hyperbolas if but are pairs of lines if . - elliptic paraboloid
horizontal traces are ellipses
vertical traces are parabolas
variable to the first power indicate axis of paraboloid - hyperboloid of one sheet
horizontal traces are ellipses
vertical traces are hyperbolas
axis of symmetry corresponds to variable with negative coefficient - hyperbolic paraboloid
horizontal traces are hyperbolas
vertical traces are parabolas - hyperboloid of two sheets
horizontal traces in are ellipses if or vertical traces are hyperbolas two minus signs indicate two sheets.
vector function (vector-valued function)
where are component function of
limit of vector function
take limit of its component function
continuity of vector function
continuous at
space curve
set of all point
- parametric equation
- parameter
- visualization
draw projection onto three plane
derivative of vector function
tangent vector
- all derivative rule apply except quotient rule
- dot product and cross product have separate rule
- inner part of chain rule must be scalar function
unit tangent vector
integral of vector function
integrate each component function
arc length
curvature
smooth parametrized curve
continuous and
(principal) unit normal vector
osculating plane
determined by
osculating circle (circle of curvature)
-
in osculating plane
-
tangent the curve
-
center towards
-
radius
binormal vector
normal plane
determined by
velocity vector
speed (magnitude of velocity vector)
acceleration vector
- Multivariate Calculus
- multivariate function
- nabla
- parametric surface
Multivariate Calculus
multivariate function
level curve (contour curve)/ level space
curve/ space with equation
- is constant
limit of multivariate function
approach as approach from any path within domain
- proof for the opposite using counterexample:
point out that the function approach different value from two different direction - the squeeze theorem hold
continuity of multivariate function
continuous
partial derivative
where
higher partial derivative
Clairaut's theorem
defined on containing , continuous
tangent plane
line approximation
increment
differentiable function
differential
for differentiable function
implicit function
implicit function theorem
given
- differentiable by and
take derivative of both side
gradient
- product rule,
directional derivative
is unit vector
only when have the same direction
level surface
level surface
line curve on the surface of the level surface
is normal vector of tangent plane
- for level curve, is perpendicular to the curve
tangent plane of level surface
extrema
point
maximum or minimum or saddle point
-
- local minimum
- local maximum
- saddle point
extrema subject to constraint
constraint
- Lagrange multiplier
for additional constraint
two constraint's intersection curve
surface area
Jacobian
line integral
piecewise-smooth curve
-
line integral of along with respect to
-
change orientation of
work
fundamental theorem of line integral
conservative vector field
vector field and s.t.
-
on open connected region,
on simply-closed region,
independence of path of line integral
with the same ends
-
closed path integral
-
is conservative
Green's theorem
positively oriented, piecewise-smooth, simple closed,
is boundary of ,
have continuous partial derivative
- extension: multiple-connected region
nabla
Laplace operator
curl
- conservative on simply-connected region,
- irrotational
divergence
- incompressible
- source
- sink
-
- Laplace's equation,
- for vector field,
- product rule,
Green's theorem in vector form
for 2-dimension
-
outward unit normal vector
parametric surface
-
grid curve
-
normal vector for tangent plane at ,
-
smooth,
-
surface integral
-
area
-
for sphere,
-
oriented surface
-
normal vector field
-
flux
Stoke's theorem
divergence theorem (Gauss's theorem)
Parametric Equation
- parameter
- parametric curve
- initial point/ terminal point
derivative
arc length
polar coordinates
- pole
- polar axis
transformation between Cartesian coordinates and polar coordinates
polar curve
graph of polar equation
area
arc length in polar coordinates
- Sequence and Series
- sequence
- series (infinite series)
Sequence and Series
sequence
list of number in definite order
sequence convergence
converge
-
-
otherwise, diverge
prove sequence convergence by function
sequence converge if corresponding function converge
- all limit law on function can be applied on sequence
sequence convergence preserve by chaining continuous function
convergence of
sequence monotonicity
increasing sequence
- the opposite is decreasing sequence
bounded sequence
bounded above
- the opposite is bounded below
- bounded sequence: both bounded above and below
monotonic sequence theorem
monotonic bounded sequence converge
series (infinite series)
or
th partial sum
series convergence
convergent
- sum of series
- the opposite is divergent
- linear combination of convergent series is convergent
example series
geometric series
power series
harmonic series
-
divergent
-series
divergence test
converge
diverge
integral test
continuous decreasing positive on
converge converge
remainder estimate for integral test
decreasing on
comparison test
converge,
converge
diverge,
diverge
limit comparison test
alternating series
alternating series test
alternating series
alternating series estimation theorem
satisfy alternating series test
absolute convergence
absolutely converge
- converge
conditional convergence
converge but not absolutely converge
conditionally converge
ratio test
root test
convergence test strategy
- special series
- -series
- geometric series
- similar form to special series
(limit) comparison test - divergence test
- alternating series test
- absolute convergence
- ratio test
- root test
- integral test
power series
power series centered at (power series about )
- coefficient
radius of convergence
converge when is within to
converge iff
converge for
converge if , diverge if
interval of convergence
-
-
-
⏎
find interval of convergence
- find radius of convergence using ratio test/ root test
- check endpoint
differentiation or integration of power series
equal to each term different or integrate
convergence and differentiability of power series
power series
has radius of convergence
function
differentiable on
-
derivative
- start from because the term at is
-
integral
function 's power series expansion
Taylor series
Taylor series of at (/ about / centered at )
Maclaurin series
Taylor series at
-th degree Taylor polynomial
-th degree Taylor polynomial of at
remainder of Taylor series
-
for
equal sum of its Taylor series
Taylor's inequality
for
for
-
used to prove equivalence between function and sum of Taylor series
-
a convergent sequence
Maclaurin series for
- let
Maclaurin series for trigonometric function
binomial series
- Complex Analysis
- complex number
- limit
- continuity
- differentiation
- harmonic function
- parametric curve
- contour
- Jordan curve theorem
- contour integral
- Cauchy-Goursat theorem
- Cauchy-Goursat theorem on simply connected domain
- adoption of Cauchy-Goursat theorem on multiply connected domain
- Cauchy's integral formula (Cauchy's formula)
- Morera's theorem
- Liouville's theorem
- fundamental theorem of algebra
- maximum modulus principle
- analyticity
- Laurent series
- singularity
- improper integral
- Laplace transform
- meromorphic
- Möbius transformation
Complex Analysis
complex number
in complex plane where
- real part,
- imaginary part,
complex plane
- real axis/ imaginary axis
- pure imaginary number,
binary operation of complex number
- addition,
- multiplication,
complex number short syntax
where
Argand diagram
diagram in given by
-
modulus, Euclidean length in Argand diagram
-
triangle inequality hold
complex conjugation
Euler's formula
- , argument of
- , principal argument of
-
de Moivre's formula
complex root
th root of
- distinct root
- principal root, when
standard topology
see context in Topology
open -neighborhood
region
nonempty connected set
- domain, open region
connectedness
is connected
polygonal line with finitely many segment between ,
bounded
circle of finite radius containing the set
complex infinity
or
Riemann sphere
intersection of the sphere with line through north poll and complex number
- north poll: , correspond to complex infinity
- Argand plane
limit
s.t.
- unique if exist
- independent of direction of approach
connection between complex limit and real limit
limit on the RHS exist
continuity
is continuous at
- exist
- exist
differentiation
differentiable at
exist
- depend on not differentiable
- differentiable differentiable
Cauchy-Riemann equations
exist at
Cauchy-Riemann equations in polar coordinate
differentiability from Cauchy-Riemann equations
defined around ,
at
- are continuous
- satisfy Cauchy-Riemann equations
exist
holomorphicity
holomorphic at
differentiable at each point in
- a.k.a. analytic/ regular
- and are harmonic function in
entire function
holomorphic at every finite point
singularity
is singularity
holomorphic in and not at
constancy from holomorphicity
holomorphic, in
is constant
holomorphic in
is constant
harmonic function
with continuous second partial derivative
parametric curve
complex-valued function
- simple does not intersect self injection
- simple closed (Jordan curve) simple except two end meet
- oriented
- positively oriented simple closed counterclockwise
- negatively oriented
parametric derivative
continuous
differentiable,
- velocity
- speed
- smooth differentiable and
-
has unit tangent vector in Argand diagram
-
parametric integral
- both real part and imaginary part commute
- antiderivative
- mean value theorem of integral fail
reparametrization
- curve length persist
parametric curve length
contour
piecewise smooth curve joined from finite smooth parametric curve
- continuous
- piecewise continuous
- vertex, point where not smooth
- length, orientation, simple closed like parametric curve
Jordan curve theorem
simple closed contour separate into
- a bounded interior
- an unbounded exterior
contour integral
contour ,
function piecewise continuous on
-
independent of parametrization
-
linearity
for contour
-
traversed in opposite direction
upper bound theorem for contour integral (ML theorem)
contour of length ,
piecewise continuous on ,
bounded by
-
proof using lemma
proof of lemma
lemma hold for . for
path independence of contour integral
continuous in
antiderivative s.t. in from to
closed,
Cauchy-Goursat theorem
on ,
simple closed contour in ,
holomorphic on and within
Cauchy's theorem
same as Cauchy-Goursat theorem, except continuous
proof using Green's theorem and Cauchy-Riemann equations
Cauchy-Goursat theorem on simply connected domain
on simply connected domain ,
closed contour in ,
holomorphic on
- simply connected domain:
every simple closed contour enclose only point in
- multiply connected domain
- holomorphic function on simply connected domain has antiderivative
- entire function has antiderivative
adoption of Cauchy-Goursat theorem on multiply connected domain
on multiply connected domain ,
positively oriented contour ,
negatively oriented simple closed contour ,
inside of and disjoint from ,
holomorphic on and on the region between
path deformation principle
for the following case, deformation of contour integral persist its value
positively oriented contour ,
holomorphic between
Cauchy's integral formula (Cauchy's formula)
positively oriented contour,
holomorphic inside and on
inside
-
derivative
-
at , holomorphic exist and holomorphic
-
holomorphic have continuous partial derivative at all order
proof
show using upper bound theorem
evaluating integral with Cauchy's integral formula
on positively oriented contour , evaluate integral
-
find s.t. inside and
-
calculate
-
apply Cauchy's integral formula
Morera's theorem
continuous on
closed contour
holomorphic throughout
Liouville's theorem
bounded entire function is constant
fundamental theorem of algebra
non-constant polynomial of degree has root
maximum modulus principle
non-constant holomorphic function on open
has no maximum on
- for on , reach maximum always on , never on interior
analyticity
analytic
Laurent series
annual domain , ,
any closed contour in ,
function holomorphic in
- punctured disk,
- unique
residue
Cauchy residue theorem
positively oriented contour ,
analytic on and within except on finite number of singularities
residue at infinity
all singularity are inside negatively oriented contour
-
Cauchy residue theorem can be rewritten as
-
by replacing with
singularity
isolated singularity
analytic in deleted neighborhood
is isolated singularity
- has Laurent series about
- not branch point
- isolated singular at infinity s.t. analytic for
essential isolated singularity
s.t.
is essential isolated singularity
-
Casorati-Weierstrass theorem
s.t
pole
s.t.
pole of order at
-
simple pole
-
removable singularity
- removed by setting
-
-
only usable for
-
for
-
zero of order
analytic at ,
,
s.t.
- identically zero
- otherwise, the zero is isolated
zero and pole
analytic,
has zero of order at at
has pole of order at
-
has simple pole at ,
improper integral
Cauchy principal value
if RHS exist
- is even
improper integral for even rational function
real, continuous, even, irreducible rational function
has finitely many zeros above the real axis
let be upper half semicircle with as its missing side
Fourier integral
Jordan's lemma
analytic above the imaginary axis outside
Jordan's inequality
indented path
lemma
Laplace transform
Bromwich formula
meromorphic
is analytic except possibly for poles
theorem for meromorphic function
simple closed contour ,
non-zero and analytic on , meromorphic within
- , number of zero of within counted with order
- , number of pole of within counted with order
argument principle
Rouché's theorem (dog on a leash theorem)
analytic on and within
Brouwer's fixed point theorem
,
analytic
s.t. (fixed point)
Hopf's theorem
closed curve ,
one can be continuously deformed into another without crossing point
Möbius transformation
-
extended complex plane
-
only singularity is simple pole
-
derivative non-zero
-
they are a group
-
map circle to circle
- line are circle of infinite radius through
circle in Argand diagram
- Complex function
- logarithm
- exponential
- trigonometric function
- hyperbolic function
- inverse trigonometric function
- Contour integral of power function on circle
Complex function
logarithm
where
- branch point
- multi-valued function
branch of logarithm
introduce s.t.
- branch cut , not continuous across
- principal branch , branch cut for principal value
- branch point , point common to all branch cut
derivative of logarithm
- holomorphic
exponential
- nonzero
- periodic,
- entire function
derivative of exponential
trigonometric function
-
entire
-
hyperbolic function
inverse trigonometric function
- are multi-valued
- holomorphic in branch
derivative of inverse trigonometric function
Contour integral of power function on circle
Complex Sequence and Series
sequence
sequence convergence
series
series convergence
converge to partial sum converge to
remainder
- converge
power series
see also power series
- converge to for
absolutely convergent in circle- circle of convergence, biggest such circle
- is continuous function inside circle of convergence
power series integration
can integrate term by term within circle of convergence
-
holomorphic
proof
let be any closed contour and set
by Morera's theorem, is holomorphic
-
can differentiate term by term
Taylor's theorem
holomorphic in
analytic,
proof using Cauchy's integral formula
when
by the upper bound theorem, for ,
as
uniqueness of Taylor series
in , power series converge to
it is the Taylor series of about
proof using power series integration and Cauchy's integral formula
Linear Algebra
determinant
Numerical Analysis
gradient descent
line search
gradient descent momentum
stochastic gradient descent (SGD)
integration
followed from Riemann sum
, partition evenly into subinterval
first-order method
second-order method
midpoint rule
Proof
proof by induction
- variable
- property
- base case
- induction hypothesis
- induction step
direct proof
contrapositive proof
implies is equivalent to implies
proof by contradiction
assume is true, get a contradiction
circular proof
to prove , need only prove
- Real Analysis
- set
- real number
- function
- sequence
- continuity
- integral
- differentiation
- sequence of function
- calculus of variation
- metric space
- series of function
- power series
Real Analysis
set
complement of set
cardinality
one-to-one correspondence
finite set
empty or has cardinality of for some
infinite set
countable set
has cardinality of
- countable, infinite and countable
- countable countable
real number
- real number are complete
every Cauchy sequence in converge to - real number satisfy the Archimedian property
Archimedian property
function
function from to is subset
is the value of at :
or
- domain
- range
- onto:
- one-to-one:
- one-to-one correspondence: onto and one-to-one
inverse function
for one-to-one function , inverse function of
sequence
or
see also Sequence and Series
sequence convergence
or converge to limit
integer , so that ,
sequence diverge to infinity
, so that ,
bounded sequence
is bounded iff
so that
- bounded monotone sequence converge
limit theorem
- bounded sequence
- squeeze theorem
- limit are linear
- multiplication and division can be extracted
Cauchy sequence
so that, if , then
- convergent sequence are Cauchy sequence
- axiom of completeness
Cauchy sequence in converge to finite number in
subsequence
subsequence of ,
limit point
limit point of
- is limit point subsequence
Bolzano-Weierstrass Theorem
bounded s.t.
- proof: successively shrink interval by half and keep the half with infinite element
- s.t.
continuity
is continuous at
-
is continuous at
continuous function on closed interval
is continuous on is bounded:
continuous on
and
and is uniformly continuous on
-
supremum
-
infimum
intermediate value theorem
continuous on , , is between
uniform continuity
is uniformly continuous
Lipschitz continuity
is Lipschitz continuous on
integral
partition
partition of is any finite collection of point
where
upper sum/ lower sum
for subinterval of partition
lower sum
upper sum
-
-
for any partition
-
for partition that contain all point of and additional point
Riemann integrability
on is Riemann integrable
-
partition s.t.
is Riemann integrable
-
continuous on Riemann integrable
Riemann integral
Riemann integrable on
Riemann integral
Riemann sum
where
-
continuous on , is sequence of partition s.t. maximum length of subinterval as , is any Riemann sum corresponding to
differentiation
continuously differentiable
differentiable on and continuous on , or
- continuous on is denoted as
Rolle's theorem
differentiable on ,
mean value theorem
differentiable on ,
Taylor's theorem
, exist on ,
where is define in Sequence and Series
-
proof
fix , let s.t.
apply Rolle's theorem time to show between s.t.
sequence of function
, defined on
sequence of function pointwise convergence
converge pointwise to limiting function
sequence of function uniform convergence
converge uniformly to limiting function
-
-
-
sequence of function , , , converge ,
-
, . , . on ,
,
supremum norm
bounded on
supremum norm or sup norm of
- sup norm is a metric
function converge in the sup norm
on converge in the sup norm to
- converge to uniformly on
Cauchy sequence in the sup norm
on is Cauchy sequence in the sup norm
- converge in the sup norm
- is complete in the sup norm
integral equation
, ,
has unique continuous solution
proof of existence
-
define any continuous and
-
show that by induction
-
show that
-
show by iteration that is Cauchy in sup norm
proof of uniqueness by contradiction: subtract equation of two solution function
calculus of variation
functional
function with domain containing function
Euler equation
is twice continuously differentiable functional of three variables
is extremal for satisfy Euler equation
metric space
metric
sequence of point in metric space converge
,
converge to
also denoted as
equivalent metric
metric on are equivalent
- in in
Cauchy sequence of point in metric space
complete metric space
contraction
is contraction
fixed point of contraction
-
stable
contraction mapping principle
complete
- has unique fixed point
series of function
-
converge s.t.
-
converge
-
linearity
limit superior and limit inferior
,
limit superior
-
- s.t.
- s.t.
limit inferior
-
- s.t.
- s.t.
partial sum
partial sum of series
- series convergence is the same as its sequence of partial sum
series convergence test
series absolute convergence
converge absolutely converge
- otherwise, conditionally converge or diverge
- is bijection (rearrangement)
- absolutely converge absolutely converge
comparison test
- converge converge
- diverge diverge
root test
- converge absolutely
- diverge
ratio test
- converge absolutely
- diverge
series of function converge
- converge to converge to
Weierstrass M-test
- s.t.
- converge
converge uniformly
integral of uniformly convergent series of function
converge uniformly to on
,
derivative of uniformly convergent series of function
- converge uniformly to on
- converge uniformly on
power series
radius of convergence of
convergence of power series
- converge on
- diverge outside
- converge uniformly on
property of in power series
- is Taylor series of about
Shorthand
DNE = doesn’t exist
near = , on
NOS = need only show
thm = theorem
WLOG = without loss of generality
WTS = want to show
Topology
set
set with all its element open
- point,
open
- closed, where
- are both open and closed
topological space
set and choice of set of open subset
- chaotic topology,
- discrete topology,
neighborhood
neighborhood of :
- deleted neighborhood,
closure
closure of ,
interior point
point
s.t.
- interior of , set of all interior point of
exterior point
point
s.t.
- exterior of , set of all exterior point of
boundary point
neither interior nor exterior of
- , boundary of , set of all boundary point of
limit point
limit point of
sequence convergence
s.t.
- in chaotic topology, every sequence converge to every point
continuity
topological space
map continuous
Package Manager
Cargo
install binary
cargo install <binary name>
update all binaries installed
cargo install-update --all
Homebrew
search package
brew search <package>
install package
brew install <package>
update
brew update \
&& brew upgrade --greedy \
&& brew cleanup \
&& brew autoremove
list installed packages
brew list
show dependency tree of package
brew deps -t <package>
display information about package
brew info <package>
clean up junk
brew cleanup && brew autoremove
Gem
install a_gem
gem instal a_gem
install all gem in project
bundle
remove outdated gems
gem cleanup
Nix
find package: search online
install prebuilt package
nix-env -ibA <PACKAGE>
install package
nix-env -iA <PACKAGE>
update all nix package
nix-channel --update && nix-env -u
check and fix nix store
sudo nix-store --verify
NPM
help node find global module (change the path if necessary)
module.paths.push("/opt/homebrew/lib/node_modules");
Pacman
get the fastest mirror (France for example)
curl -s "https://archlinux.org/mirrorlist/?country=FR&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 -
set mirror
sudo vim /etc/pacman.d/mirrorlist
resolve untrusted packages when updating
sudo pacman -Sy archlinux-keyring
pip
always use python3 -m pip instead of pip
- make sure using the same pip as python
- use
python -m pipon Windows
upgrade pip3
python3 -m pip install --upgrade pip
update all
python3 -m pip list --outdated --format=json \
| python3 -c "import json, sys
print('\n'.join([x['name'] for x in json.load(sys.stdin)]))" \
| grep -v '^\-e' \
| cut -d = -f 1 \
| xargs -n1 python3 -m pip install -U
check version
python3 -m pip -V
remove cache
python3 -m pip cache purge
Programming
C
type
primitive type
charintfloatdoublelong
and the unsigned variant
array
d0 × d1 × … × dn int array
int arrayName[d0][d1] /*…*/[dn] = {
{ /*…*/ },
/*…*/
};
- can declare without initializing
- if value given, can omit
d0 - can just supply one array and it will split
- array is pointer to the first element
string
char array, null terminated
immutable string
char* name = "text";
mutable string
char name[] = "text";
-
in this case, same as
char name[5] = "text";
string method
strlen(str)length ofstrstrncmp(str0,str1,n)comparestr0andstr1to at mostnstrncat(dest, src, n)concatenatesrctodestfor at mostn
function
declare before use
empty declaration is fine
static
static variable
near global variable (file only)
- won't initialize twice if in a function
static function
file scope function
pointer
number representing memory address
explicitly create pointer
int* ptr = &8;
implicitly convert to pointer
char* ptr = "bla";
struct
declare struct
struct keyword
struct point {
int x;
int y;
};
struct point p;
p.x = 0;
p.y = 0;
typedef keyword
typedef struct {
int x;
int y;
} point;
point p;
recursive definition
typedef struct node_t {
int val;
struct node_t* next;
} node;
access struct's field
.->for pointer struct
nested struct
typedef struct {
struct {
int x;
int y;
};
int z;
} nested;
- access inner struct's field directly from the outer struct
union
struct with overlapped field
typedef union {
int theInt;
char chars[4];
} intChar;
- field in union share the same bytes
- read field of union like read field of struct
- assign to union itself assign the the first field
union for struct index
union Coins {
struct {
int quarter;
int dime;
int nickel;
int penny;
};
int coins[4];
};
dynamic allocation
person* p = malloc(sizeof(person));
malloc return void pointer, implicitly converted
explicitly typecasting has the same effect
person* p = (person*) malloc(sizeof(person));
clean the dynamic allocation
free(person);
dynamically allocated array
int* arr = malloc(n * sizeof(int));
- do not need to know size at compile time
- can index
arr[i]like ordinary array
pointer arithmetics
- incrementing pointer skip an amount of byte according to the pointer type
- e.g.
int*skip by 4 byte
- e.g.
pointer function
int real_function(int n) {
return n * n;
}
int (*function_name)(int arg) = &real_function;
- used as argument in another function
call pointer function
(function_name)(5);
array of pointer function
void f1();
void f2();
void (*function_name[2])() = {&f1, &f2};
Elixir
print Charlist as list of integer
[1, 2, 3] |> inspect(charlists: :as_lists) |> IO.puts()
function
anonymous function
f = fn arg0, arg1, … -> result end
need a dot to call
f.(a0, a1, …)
capture syntax
&fn1/n_args
&(&1…)
&1for the first argument,&2for the second, etc.
Git
start using git
git init
check status
git status
show all difference since last commit
git diff
git clone without downloading
git clone <repo> --no-checkout
commit with message
git commit -m "<msg>"
stage all changes and commit
git commit -am "<msg>"
revert to the last commit
git reset HEAD~
or
git revert …
change the last commit
--amend
add repo as submodule
git submodule add <repo>
push book folder to GitHub gh-pages to publish pages
git subtree push --prefix book origin gh-pages
push all branch to all remote
git remote | xargs -L1 git push --all
push master to all remote
git remote | xargs -L1 -I R git push R master
pull every repo under the current folder
fd .git -H -t d -x git --git-dir={} pull
fetch and status every repo under the current folder
fd .git -H -t d -x git --git-dir={} fetch \; -x git --git-dir={} --work-tree {}/.. status
delete all history of a certain file (deprecated)
git filter-branch --index-filter \
'git rm -rf --cached --ignore-unmatch <path_to_file>' HEAD
delete all history of a certain file using git-filter-repo
git filter-repo --invert-paths --path '<path_to_file>' --use-base-name
ignore all symlink
find * -type l -not -exec grep -q "^{}$" .gitignore \; -print >> .gitignore
check what are the branches
git fetch && git branch
check out another branch
git checkout <branch>
create orphan branch
git switch --orphan <branch>
force sync from origin
git reset --hard origin/master
- Java
- built-in data type
- basic syntax
- input
- output
- class
- generic programming
- functional programming
- package
- timing
Java
built-in data type
primitive type
bool
1B
-
&&||!assert (a && b) == (!(!a || !b))
number
-
two's complement, e.g.
Integer.MAX_VALUE + 1 = Integer.MIN_VALUE = -Integer.MIN_VALUE
short
2B
int
4B
float
4B
long
8B
double
8B
- special value
InfinityNaN
numerical operator
- cast to precise type when different type
+ - */integer division if both integer else float division%remainder
Math library
operation: abs, max, sin, asin, exp, log, pow, round, random, sqrt variable: PI, E
char
2B
- use ASCII
- auto cast from and to int
convert to String
String.valueOf(charArray)
cast
(target_type) var_to_convert
wrapper type
built-in reference type corresponding to primitive type
- object
- autoboxing and unboxing convert from and to primitive type and wrapper type automatically in assignment and function call
String
concatenation
-
+
string1.append(string2)
StringBuilderbetter way to concatenate string
array
{literal1,…}//an array
arr1.length//length attribute of array
Arrays.sort(arr1)//sort array arr1
- copy: copy the length and every single value
- assign: refer to the same array (aliasing)
- array overhead 3B = object reference 1B + object overhead 2B
declaration
type1[] arr1; //declare array name of type type1
initialization
new double[length] //an array of length length, all 0.0s
- default value for number is 0
- default value for object is
null
access & mutate
arr1[i] = literal; //refer to array arr1 by index i
two-dimensional array
an array of array
basic syntax
conditioning
if
if (bool1) { execution1; }
else if (bool2) { execution2; }
// …
else { execution0; }
switch
switch (var1) {
case value1: execution1;
break;
// …
}
- work with primitive type and wrapper
- work with enum
- work with String
loop
while
while (bool1) { execution; }
do while
do { execution; } while (boolean);
at least do once
for
for (initialization_statement1, …; bool1; increment_statement1, …) { execution; }
access modifier
default
access from same package
public
public …;
access everywhere
protected
protected …;
access from same package or subclass
private
private …;
access from same class
mutability modifier
final … var1 …;
make the variable immutable
static vs instance
… static …;
make variable or function static, as opposed to instance
- static mean belong to type itself
- instance mean belong to an instance of class
comment
// inline
/* block */
docstring
/**
* doc
*/
support HTML
assertion
assert bool1 : "error message";
throw the error if bool1 == false
input
command-line argument
args[i]
- start from
0
stdin
scanner:
import java.util.Scanner; //import scanner
Scanner sc= new Scanner(System.in); //define a scanner
Type1 var1 = sc.nextType1();//let variable be input
output
System.out.println(output)//print output \n
System.out.print(output)//print output
formatted print
System.out.printf(“string1%w1.p1c1… string2”,output1,…)
//print string1 output1… string2
// with field width w, precision .p, and conversion code c
- negative
wcounts from the right - for c
d: decimalf: floatinge: scientifics: stringb: boolean
- must have
%andc - standard string format in Java
class
class as function library
public class ProgramName {
public static void main(String[] args) {
// main function
}
}
global variable
public class ProgramName {
static type1 var1;
}
class as abstract data type
public class ClassName {
type1 ins1; // instance variable …
/*
* constructor
*/
public ClassName(arg…) {
// …
ins1 = …; // need to initialize all instance variable …
}
public type2 method1(arg…) {
// …
} // instance method …
public static void main(String[] args) {
// test
}
}
- use short name for instance variables for convenience
- use full name for parameter variables as the client can see them
constructor
same method name as class
use constructor
ClassName var1 = new ClassName(arg…);
access instance variable
var1.ins1
use instance method
var1.method1(arg…);
common instance method
equals method
public boolean equals(Object x)
{
if (x == null) return false;
if (this.getClass() != x.getClass()) return false;
return (this.ins1 == x.ins1) && …;
}
hashCode method
public int hashCode() {
return Objects.hash(ins1,…);
}
interface
public interface InterfaceName {
type1 var1; // instance variable …
public abstract type1 method1(arg…); // empty abstract method …
}
- interface enables a method name to call different methods according to the object
- functional interface: single method
abstract method
include nothing
implement
public class ClassName implements InterfaceName{
// …
}
- the class must have methods corresponding to all abstract methods in the interface
implement Iterator
import java.util.Iterator;
class ClassName implements Iterator<K> {
// …
// must-need method for Iterator
public boolean hasNext() {
// …
}
public Item next() {
// …
}
public void remove() {
// …
}
}
subclass
public class SubClassName extends ClassName {
// …
}
have everything super class have
generic programming
generic class
public class GenericClass<typeParameter> {
// …
}
a class that can be fed with different data type
use constructor
GenericClass<type1> var1 = new GenericClass<type1>(var0);
functional programming
lambda expression
(arg…) -> stuffToReturn;
package
import
static import
import static package1
imports the method so that its prefix can be omitted don’t use
timing
System.currentTimeMillis()
System.nanoTime()
JavaScript
data type
- no char
- undefined
- nullish coalescing operator
??
give default value if the expression before isnullorundefined - optional chaining
?
skip method chain and returnundefinedif expression before isundefined
- nullish coalescing operator
assignment
- fallback
||execute if the former one fail
array […]
can contain multiple types of data
access data array1[index1]
.length.push().pop()work like stack.unshift().shift()work like queue.splice(index,number,…)removenumberitems fromindexand insert….reduce(fun1)take variable into function and put result back- spread (deep copy)
[...arr1] - rest
[attr1, ...arr2] = arr1
loop array
- the C way
for… ofloop.forEach(callback)
string
is just immutable array
formatted string
`blah ${var1}…`
.toUpperCase().toLowerCase().trim().slice(start,end)a.slice(1)return substring excludinga[0]a.slice(-1)returna[a.length - 1]
function
function fun1(var1,…) {
// …
}
anonymous function
(var1,…) => {
// …
}
minimum var1 => expression1
comparison
- strong comparison
===!==does not convert type - weak comparison
==!=convert type
object
{
attr1: lit1,
// …
}
rather dictionary
deleteattribute.hasOwnProperty(attr)check if hasattr- rest
{attr1, ...obj2} = obj1 - spread
obj2 = {...obj1, attr1: val1}
quick initialization
{
attr1,
attr2,
// …
}
is equivalent to
{
attr1: attr1,
attr2: attr2,
// …
}
access attribute
.attr1object1[attr1]
immutable object Object.freeze(…)
method
defined inside of the object block
class class Class1{…}
constructor constructor(…){…}
use constructor new
getter/setter get var1() {…}/set var1(…) {…}
MathJax
enable $…$ inline math
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: {inlineMath: [["$","$"]]} })
</script>
- Julia
- built-in
- variable
Julia
use latex symbol
type \… and tab
built-in
constant
π or pi = 3.1415926535897...
Inf and NaN
im
math function
sqrt()
variable
check type
typeof()
numerical type
extreme representable value
typemin(Type1) / typemax(Type1)
convert to bits bitstring()
avoid overflow using big()
create BigInt or BigFloat
or use big"…" if the number if too big for Int or Float
machine epsilon eps(Type1)
implicit numeric multiplication
2x^2x is equivalent to 2 * x^(2 * x)
arithmetic operation
÷integer division^power.make the next operator element-wise
e.g..+element-wise add
numeric comparison
Julia support real Unicode operator
isequal()compare objectisfinite()isinf()isnan()
Julia support arbitrary comparison chaining
conversion Type1(…)
pattern matching
_ can be assigned value
string
Use double or triple quote for string literal
index take raw bytes
index start at 1
can use begin and end for index
r"…"regex stringb"…"byte stringv"…"version literalraw"…"raw string
string concatenation
string(str1, str2, …) combine multiple string
str1 * str2 concatenate them
"$str1 and $(str2)." formatted string
tuple and list
(a, b, c)tuple[a, b, c]list
match tuple or list or variable length
first, second, rest... = (a, b, c, d, e)
# rest = (c, d, e)
function
traditional syntax
function func1(args)
# …
end
assignment form
func1(args) = # …
- the last expression is returned
nothingis returned without a return value
function argument type annotation
func1(arg1::Type1, …)
optional argument
func1(arg1, opt_arg1=default_val1, …)
- optional argument are positional
keyword argument
func1(arg1, ¬; keyword_arg1=default_val1, …)
- keyword argument must have the keyword specified when called
- keyword argument does not need a default value, but then it will be mandatory
- keyword name is implied as the variable name if it appear after
;when called
function taking function as argument
func1(f::Function, arg2, …)
-
call with named function
-
use with anonymous function
func1(x -> …, val2, …) -
use with do-block
func1(val2, …) do arg1_for_function_passed_in, … # … end
dispatch
function can have different method for different type
anonymous function
(args…) -> # …
or
function (args)
# …
end
function composition
(f ∘ g)(args)
is equivalent to
f(g(args))
function chaining (function piping)
args |> g |> f
is equivalent to example above
use piping with broadcasting
.|> apply piping element-wise
vectorize function
func1.(args)
apply func1 to each element in each argument, equivalent to
broadcast(f, args)
Lua
data type
nil
string
str1 .. str2 concatenation
string.format("literal and %s…", variables…) formatted string
boolean
only false and nil are falsy
map
map1 = {
key1 = val1,
-- …
}
loop through map in order
for index, element in ipairs(map1) do
-- …
end
pairs loop not necessarily in order
#map1 length
array
array is just map with key 1, 2, 3, …
insert element into array in order
list = {}
for element in iterable1 do
table.insert(list, element)
end
sort array
table.sort(list)
arithmetic operation
~ not
~= not equal
variable
- variable are global by default
localmake variable local
function
function func1(args)
-- …
return …
end
- missing argument is nil
{ ... }put
use a variable amount of argument
function func1(...)
local args = { ... }
-- …
end
condition
if statement
if bool1 then
-- …
else if bool2 then
-- …
end
else
-- …
end
while statement
while bool1 do
-- …
end
for statement
for element in iterable1 do
-- …
end
emulate ternary operator (neither option can be falsy)
result = bool1 and option1 or option2
input/output
command line argument
local args = { ... }
get script file parent directory
debug.getinfo(1).source:match("@?(.*/)")
get home directory
os.getenv('HOME')
run command
function run_command(command, pattern)
handle = io.popen(command)
result = handle:read(pattern or "*a")
handle:close()
return result
end
module
load a module
mod1 = require("mod1")
reload module eagerly
(Lua does not read the file again by default at the second require)
local function use(module)
package.loaded[module] = nil
return require(module)
end
create a module
- file name is module name
Mod1 = {}
function Mod1.func1(args)
-- …
end
return Mod1
Perl
install package A/B
cpanm install A::B
- Python
- environment
- variable
- data type
- function
- loop
- scope
- class
- module
- package
- file input/ output
- file
- regular expression (regex)
- mistake
- comment
Python
environment
- Python REPL (Read-Evaluate-Print Loop)/ Python shell
- script script file
variable
operator
- assignment operator
=
naming convention
- camelCase
- snake_case
PEP 8 guideline
inspect (in REPL)
unassign (delete)
del var1
data type
- fundamental data type
- compound data type (data structure)
- check data type
type()
string str
- character
- length
len(string1) - sequence
string literal "string literal"
-
delimiter
""or'' -
multiline string
"first and \ second"or
"""first line second line""" -
raw string
r"raw string"
string operation
- concatenation
string1 + string2
need to manually make sure both are string - indexing
string1[index1]→ character
negative index count from right - slicing (slicing)
string1[index1:index2]
return string consisting ofstring1[index1]tostring1[index2 - 1]
leavingindex1orindex2empty means0or-1by default
exceeding string length return empty string''for those parts - multiplication
string1 * nrepeatntime
immutability
string method
- convert case
.lower().upper() - remove whitespace
.rstript()from the right
lstript()from the left
stript()both side - check start/ end
.startswith().endswith()→ boolean - find substring
.find(substring1)→ int index of the first found;-1if not found - replace
.replace(string1,string2)
input
input(prompt_string) → str
string conversion
- anything to string
str(var1)
output
-
print(string1, string2…)
each part must be string
' 'are added between string -
formatted string literals (f-string)
f"{string1}string_literal…"→ strenclose variable name in
{}
number int float
number literal 1
- separate by
_ignored - exponential notation (E-notation)
1e2→ float - too big →
inf/ too small →-inf
arithmetic operation
- operand and operator
- addition
+subtraction-multiplication*→ int iff both operand int, else float - division
/→ float - integer division
//→ int iff both operand int, else float, round down
no0denominator allowed regardless of type - exponent
**→ int iff both operand positive int, else *float - modulus
%→ int iff both operand int, else *float
number method
- round tie to even
round(num1,n)
by default, blank precision → int withNoneprecision
with intn→ int iff both int, else float withnfloating digit (negative precision go beyond decimal) - absolute value
abs()return same type - power
pow(base1,exponent1) = base1 ** exponent1,pow(base1,exponent1,mod1) = (base1 ** exponent1) % mod1 - check if float is int
float1.is_integer()→ boolean
number conversion
- string to int
int(string1)can only take string in integer form
output
fixed-point number f"{num1:format}"
format language format
.ptprecisionptypete.g..2f.pt%in percentage form,separate digit with comma
complex number
format n =num_real + num_imaginej
- getting real part and imaginary part
n.realn.imag→ float - conjugate number
n.conjugate()
*intandfloatalso have these
None NoneType
no data
data structure
tuple
- ordered sequence (iterable)
- immutable
- can hold multiple type of element at the same time
tuple literal (elem1,…)
- empty tuple
() - tuple with only 1 element
(element1,)
built-in create method
tuple(converted1) convert iterable converted1 into tuple
length len(tuple1)
indexing tuple1[index1]
slicing tuple1[index1:index2] → shallow copy
packing/ unpacking
- packing
tuple1 = elem1,… - unpacking
var1,… = tuple1 - combined
var1,…,varN = literal1,…literalN
check contain elem1 in tuple1 → boolean
list
- same as tuple
- mutable
- use
[]
create
list(iterable1)string1.split(separator1)- list comprehension
[expression1 for elem in iterable1]
mutate
- replace element
list1[index1] = elem1 - slice replace
list1[index1:index2] = list2not necessarily same length - insert
list1.insert(index1,elem1)
index too big is seen as last index - append
list1.append(elem1)append to last space, equivalent tolist1.insert(list1.__len__(),elem1) - extend
list1.extend(iterable1)append an iterable - pop
list1.pop(index1)return and removelist1[index1]
list method
- sum number
sum(list1)iff all element are number min()max()- shallow copy
list1[:]orlist1.copy() - sort
list1.sort()
keylist1.sort(key=func1)sort by return value offunc1(elem)
dictionary
- key-value pair
create dictionary
- dictionary literal
{key1:val1,…} - from tuple of tuple
((key1:val1),…) - empty dictionary
{}ordict()
access
dict1[key1]→ value corresponding- index
dict[index1] - convert to dict_items
dict1.items()
mutate dictionary
- add or overwrite
dict1[key1] = val1 - remove
del dict1[key1]
set
dictionary without value
create set
set(a) # or
{a, b, c}
set method
some method map to arithmetic operator but those only work on other set instead of any iterable
.union(iter1)≈|.difference(iter1)≈-.symmetrical_difference(iter1)≈^issubset(set1)≈<=issuperset(set1)≈>=
function
- argument
- return value
- side effect
property
function are values
function name are variable
side effect
change something external to the function itself
anatomy
- function signature
def fun_name(parameter_list): - function body
fun_signature
fun_body
parameter
placeholder for variable
- default value
fun_name(para1=val1,…)
return statement return return_value
automatically return None if no return statement
call function_name(args,…)
built-in function
- get the usage of the function
help(fun_name)
user-defined function
- define first and then call
- docstring—triple-quoted above function body
loop
while loop
- while statement
while test_condition: - loop body
for loop
- for statement
for membership_expression: - loop body
- else statement
else:execute if not break
membership expression
a in bi in range(n)
break out
exit loop break
next iteration continue
scope
- local scope
- global scope
- enclosing scope
LEGB rule
Local Enclosing Global Built-in
- violate scope
global var_namelet local access global
class
class Class1: CamelCase
empty structure to contain data
dunder method .__method1__()
local method _method1() naming convention
(instance) method
function in class
- change what is printed
.__str__()
instance
object built from class
instantiate
Class1(para1,…)
attribute
mutable
class attribute
variable with initial value every object of this class has, defined right under the class structure
instance attribute
- initialize method
.__init__()def __init__(self,para1,…):
access object1.attribute1 dot notation
inheritance
- create child class
class ChildClass1(ParentClass1): - common ancestor
object - check class and parent class of instance
isinstance(object1,Class1)
method inheritance
- completely overwrite parent method
- access parent (direct, not grand) method using
super().method1(arg1,…)
module
calling module import module1
variation (can be combined)
import module1 as name1from module1 import name1,…
namespace module1 in module1.name1
specify different options for import and ran directly
if __name__ == '__main__':
package
a folder to group modules
must-have module __init__.py
for the package to be recognized
import module from package import package1.module1
from package1.module1 import name1
subpackage
a package under a package
package manager
automate install, update, remove of third-party package
de facto package manager pip
virtual environment is used to make sure things work after some update
file input/ output
path library module pathlib
Path object
- file or directory name
path1.name - component of file name
path1.stempath1.suffix - check existence
path1.exists()→ boolean - check if is file
path1.is_file()→ boolean - check if is directory
path1.is_dir()→ boolean
create
- from string
Path(string1) Path.home()orPath.cwd()path1 / string1orpath1 / path2
absolute/ relative path
absolute path
start from root
- test
path1.is_absolute()→ boolean - access root directory
path1.anchor
relative path
start from cwd
path1.anchor→''
path component
all level of directory from low to high path1.parents → iterable
one level up path1.parent → Path
manipulation
- make directory
path1.mkdir()
avoid error if directory already existpath1.mkdir(exist_ok=True)
create all the parents directory if not existpath1.mkdir(parents=True) - make file
path1.touch()
trying to make file that already exist do nothing - iterate all content of directory
path1.iterdir()→ iterable - move
src_path1.replace(des_path1)overwrite destination by default - delete file
path1.unlink()
avoid error if not existpath1.unlink(missing_ok=True)
search for file in directory
path1.glob(pattern1) → iterable
- wildcard character
*—any number of character?—1 character[abc]—any included character
- match to a pattern
- recursive matching
use**/search in the subtree
or usepath1.rglob(pattern1)
shutil module
remove subtree shuril.rmtree(path1)
os module
both pathlib and shutil are implemented using os
file
text file
character encoding
line ending
- carriage return
\r - line feed
\n
csv file
csv module
write
- writer object
csv.writer(file1)- write one line
writer1.writerow(list_of_str1)add','between all item and\nat the end - write multiple lines
writer1.writerows(list_of_list_of_str1)
- write one line
- dictionary writer object
csv.DictWriter(file1,fieldname=list_of_str1)- write header
DictWriter1.writeheader()→ int of character written - write one line
DictWriter1.writerow(dict1) - write multiple line
DictWriter1.writerows(list_of_dict1)it in fact work with any object withwrite()method
- write header
read
- reader object
csv.reader(file1)→ iterable of list of str - dictionary reader object
csv.DictReader(file1)→ *iterable of dict ofheader:val
binary file
can only interact with byte directly
file object
create
path1.open() from pathlib
- mode
path1.open(mode=mode1)"r"—read"w"—write"a"—append"~b"—for binary file with~be one of the mentioned
- encoding
path1.open(encoding=encoding1)."ascii""utf-8"
open(string1) built-in
exactly like path1.open() except using a string
with statement with … as file1:
close file1.close()
read
- all at once
file1.read()→ str - line by line
file1.readlines()→ iterable of str
write
create file if not exist and parent exist
write a string
file1.write(string1) → int of character written
- overwrite when in write mode
- append when in append mode
write a list of string
file1.writelines(list1)
regular expression (regex)
meta-character
wild card
*any number of the character left to it, greedy, excluding\n.a character, excluding\n*?any number of the character left to it, non-greedy, excluding\n
string method
- find all
re.findall(pattern_string1,checked_string1)→ list of str - not case sensitive
re.meth1(…,re.IGNORECASE) re.search(pattern_string1,checked_string1)→ MatchObjectmatch_object1.group()→ the first greedy result
- find replace
re.sub(pattern_string1,replace_string1,checked_string1)
mistake
error
- syntax error
- run-time error
try
try:
execution1
except error_name:
execution2
finally:
execution3
- multiple kinds of error
except (error_name1,error_name2): - catch error individually using multiple
except - bare exception clause
except:catch any error
comment
- block comment
# block comment - in-line comment
code # in-line comment - document code
docstring"""description of this program"""
Mathematica
- space is seen as $\times$
approximation
exact result by default, to get approximation
- add a dot at the end
…. - use
N[]
complex number
imaginary unit I
variable assignment
- unassigned variable treated as symbol
- assigned variable work like in other language
- clear variable
Clear[]
data structure
list `{…,…}
- getter
list1[[index1]] - slicing
list1[[start1;;end1]] - show as list
FullForm[]
vector
vector are represented as list
- dot
.orDot[,] - cross
esc+cross+escorCross[,]
matrix
a list of list
- show as matrix
MatrixForm[]
hide output ;
force simplify Simplify[]
math function
define f[var1_]:=…
calculate f[…]
integration
- indefinite
Integrate[fun1[var1],var1] - definite
Integrate[fun1[var1],{var1,start1,end1}] - numerical
NIntegrate
equation
polynomial
SolveValue[] gives precise solution
NSolveValue[] gives approximate solution
non-polynomial
FindRoot[] uses Newton's Method
plot
search help
MATLAB
syntax
number
special variable
- most recent answer
ans - accuracy of floating-point precision
eps
special constant
- not a number
Nan -
Inf -
iorj -
pi
numerical operator
- plus
+minus- - matrix multiplication
* - array multiplication
.* - matrix exponential
^ - array exponential
.^ - left-division
\ - array left-division
.\ - right-division
/ - array right-division
./ - square root
sqrt()
character syntax
- regularly spaced elements or entire row or column
: - enclose function argument, array index; override precedence
() - enclosure array element
[] - decimal point
. - line-continuation
... - separate statement and element in a row
, - quote sign and transpose
_ - non-conjugated transpose
._
semicolon ;
- end of statement
- hide output of statement
percentage sign %
- inline comment
% comment - multiline comment
% {
comment
% }
save and load
- save all variable in workspace as
.matfilesave file_name - load the file
load file_name
variable
assign
- all variable is either array or matrix
- no
nulltype - unassigned value are assigned to
ans - long assignment
var1 = command1 ...
command2
- declare global variable
global
vector
1D array
- row vector
[num1 …] - column vector
[row1;…]
matrix
2D array
[r1c1 r1c2 …; r2c1 …]
solve
x = A\B
variable management
- display all variable name
who- with information
whos
- with information
- delete all variable
clear- delete variable
var1clear var1
- delete variable
- check existence of variable
exist var1
session management
shell environment
- open shell
matlab -nodisplay -nodesktop - close shell
quitorexit
file system
- shell script
cddirdeletepwd
format format arg1
- short format (default, 4 decimal place)
format short - display 16 decimal place
format long - display 2 decimal place
format bank - display in exponential form
format arg1 e - display as the closest rational form
format rat
find help
- help topic
help - search help entry
lookfor
MIPS Assembly
register
$0: always 0$v0,$v1: expression evaluation and function return value$a0~$a3: argument$t0~$t9: temporary variable saved by caller$s0~$s7: temporary variable saved by callee$gp: global area pointer$sp: stack pointer$fp: frame pointer$ra: return address
memory declaration
.data
var0: .word number0, number1, …
var1: .space number_of_bytes
var2: .byte character0, character1, …
var3: .asciiz string
var4: .float floating_point_number
.text
.align 2
.global main
main: …
function0: …
line label
label: instruction0
…
inner label
start with underscore to distinguish from function
instruction format
| opcode | operands |
|---|---|
| 6 bits | 26 bits |
- Op: opcode
- Rs: source register
R-type
| name | Op | Rs | Rt | Rd | Sh | Func |
|---|---|---|---|---|---|---|
| bits | 6 | 5 | 5 | 5 | 5 | 6 |
- Rt: the other source register
- Rd: destination register
- Sh: shift register
- Func: function code
I-type
| name | Op | Rs | Rt | Immed |
|---|---|---|---|---|
| bits | 6 | 5 | 5 | 16 |
- Rt: target register
- Immed: immediate value
| name | Op | Target |
|---|---|---|
| bits | 6 | 26 |
system call syscall
- load syscall code into
$v0 - put argument into
$a0,$a1,$f12(float) syscall- return value in
$v0,$f0(float)
syscall code
- 1: print integer
- 2: print float
- 3: print double
- 4: print string
- 5: read integer
- 6: read float
- 7: read double
- 8: read string
arguments: buffer, length - 9: sbrk (malloc)
- 10: exit
Racket
language type
specify the language used in the first line of a program
#lang racket
data type
string
string literal can have new line
boolean
#t #f
- non-
#fare considered#t
variable
(define var_name expression)
function (procedure)
(define (func_name args) (output))
call function
(func_name args)
special form
(if test1 do_if_true do_if_false)
(cond (test1 do_if_test1)
(test2 do_if_test2)
(else fallback_expr))
(begin first_thing_to_do second_to_do)
Ruby
string
string literal
simple string
'parsed as is'
string considering \
"string where \nis parsed"
formatted string
str = "yes
"say #{str}"
match string
match a string with regex and return index of match
str =~ regex
match string with regex and name each part
comp = /\[(?<comp1>.*)\](?<comp2>.*)/.match(str)
comp1 = comp[:comp1]
comp2 = comp[:comp2]
get all word from string
str1.split(/[^[[:word:]]]+/)
array
arr = [ "a", 1, true ]
arr[0] # => "a"
arr[1, 2] # => [ 1, true ]
array method
.length .push(ele) .pop
# loop through
arr.each do |ele|
# …
end
# join with `str`
arr.join(str)
# map
arr.map do |ele|
# …
end
# map with index
arr.map.with_index do |ele, index|
# …
end
string array
%w(this will be split) # => [ "this", "will", "be", "split" ]
hash
# old way
ha = {
'a' => 1,
'b' => 2
}
ha['a'] # => 1
ha['c'] # => nil
# new way
ha = {
'a': 1,
'b': 2
}
ha[:a] # => 1
block
{ |args|
# …
}
# or
do |args|
# …
end
call block
yield {|ele| puts ele}
control flow
if
if a
# …
elsif b
# …
else
# …
end
case
case a
when b
# …
when c
# …
end
while
while a
# …
end
statement modifier
do_something if a
function
yield execute a block
eval evaluate a string as code
define function
def func1(arg = default_value)
# …
# return last expression
end
main function
if __FILE__ == $0
# main function
end
class
class ClassName
# called with `new`
def initialize(arg)
# …
end
end
instance variable
@name
access instance variable
attr_accessor :name
method
# all instance method of class
ClassName.instance_methods
# instance method excluding inherited
ClassName.instance_methods(false)
inherited method
.respond_to?(str) check if object has method str
.to_s convert to string
.nil? check if nil
static method
def self.static_method_name(arg)
# …
end
safe navigation syntax &.
same as optional chaining
module
module ModuleName
def self.static_method1
# …
end
end
exception
class CustomError < RuntimeError
end
Rails
new rails project
rails new <project_name>
start rails server
rails s
routing
in config/routes.rb
Rails.application.routes.draw do
# root route is special
root 'articles#index'
# non-root route like this
# trigger `index` action in `articles` when GET request on `articles`
get 'articles', to: 'articles#index'
# route with variable use `:`
# the variable is passed to controller in the hash `params`
# in this case `params[:id]`
get 'articles/:id', to: 'articles#show'
end
resourceful routing
Rails.application.routes.draw do
resources :articles
end
this map route
| URI pattern | controller#action |
|---|---|
| articles | articles#index |
| articles/new | articles#new |
| articles/:id | articles#show |
| (POST) articles | articles#create |
| articles/:id/edit | articles#edit |
| (PATCH) article/:id | articles#update |
| (DELETE) article/:id | articles#destroy |
and set up URL and path helper method
| method | return |
|---|---|
| article_path | "articles/#{article.id}" |
model
in app/models
- singular name
generate model
generate model Article with two field
rails g model Article title:string body:text
- also generate database migration
generate and save new model object
# generate new article object
article = Article.new(title: 'Example', body: 'Example text.')
# save to database
article.save # => true
update model object
article.update # => true
validation of model object when save or update
# declare a `article_params` method to validate
def article_params
params.require(:article).permit(:title, :author, :body, :status)
end
# use the method when try saving or updating
if @article.update(article_params)
redirect_to @article
else
render :edit, status: :unprocessable_entity
end
query model object from database
# query article by id
Article.find(1) # => 1 Article object or Nil
# query all articles
Article.all # => 1 ActiveRecord::Relation object
view
in app/views
html.erb file
embedded Ruby in HTML
-
run ruby code
<% … %> -
run ruby code and render the return value
<%= … %> -
write comment that does not render in result
<%# comment %>
access instance variable in view
<ul>
<% @articles.each do |article| %>
<li>
<%= article.title %>
</li>
<% end %>
</ul>
link to other page in view
-
product a link with some_text to
article_path<%= link_to some_text, article %> -
redirect to show a model object
redirect_to @article- the browser make a new request
- use
redirect_toto mutate database
-
render image
<%= image_tag image_path %> -
link to the same page with different params
<%= link_to some_text, url_for(params.permit!.merge(field_to_change: field_value)) %>
partial template
partial has name starting with _
e.g.
_form.html.erb
access partial template from another view
<%= render 'comments/form' %>
-
relative path without
_ -
add argument
render 'form', article: @article # or the longer format render partial: 'form', locals: { article: @article } # or even longer format render partial: 'form', object: @article, as: 'article' -
render a collection
render @products # or longer format render partial: 'product', collection: @productsor even longer format
<% @products.each do |product| %> <%= render partial: "product", locals: { product: product } %> <% end %>
controller
in app/controllers
controller for articles is articles_controller.rb
- plural name
generate controller
generate ArticlesController and its index action
rails g controller Articles index
by default,
index action of Articles render app/views/articles/index.html.erb
instance variable in controller
instance variable in controller can be accessed in view
# this will be accessed in `articles/index.html.erb`
def index
@article = Article.all
end
controller method for resourceful routing
index method in controller
show method in controller
need to query model object by params[:id]
new method in controller
only initialize new model object
create method in controller
assign value to new model object and attempt to save it
def create
@article = Article.new(title: '…', body: '…')
if @article.save
redirect_to @article
else
render :new, status: :unprocessable_entity
end
- strong parameter
database
SQLite3 by default
migration
in db/migrate
rails db:migrate
console
open a rails irb console
rails console
Hotwire
Turbo
- Rust
- function
fn - variable
- type
- statement
- expression
- reference
- input/ output
use std::io - macro
- comment
- package
- closure
Rust
function fn
main function
fn main(){}
associated function
a function that is implemented on a type
#![allow(unused)] fn main() { `type1::fun1()` }
method
- call method on instance
#![allow(unused)] fn main() { instance1 .method1(); }
variable
immutable by default
declare
let
- declare mutable variable
let mut
type
String
new string String::new()
str
#![allow(unused)] fn main() { "str literal" // str literal r#"str literal"# /* raw str literal */ }
enumeration
variant
result Result
enumeration with variant Ok or Err
Ok variant
indicate successful run, contain result
Err variant
indicate failure, contain reason
.expect() method
crash on Err and display argument
statement
represent instruction for action
end with ;
expression
represent a value
end without ;
can be used as return statement
reference
- refer to variable
&var1 - mutable reference
&mut var1
input/ output use std::io
input
io::stdin()→ an instance of typestd::io::Stdin- standard input handle type
std::io::Stdin
macro
print println!()
debug print dbg!()
pass it a reference because it take ownership of argument
todo todo!()
unreachable unreachable!()
comment
inline comment //
package
crate
root convention
- binary crate root
src/main.rs - library crate root
src/lib.rs
both same name as package
import crate use
- absolute path
crate::… - relative path
self::…
import function
use the parent path
import struct or enum
use the whole path
alias
use … as …
re-exporting
pub use …
nesting path
- both are children
use common_path::{path1,path2…} - parent and children
use common_path::{self,path1…}
glob operator *
brings everything into scope
trait
define
pub trait Trait1 {…}
trait method
-
empty method
#![allow(unused)] fn main() { `fn fun1(&self,…)->Type1;` } -
default implementation
#![allow(unused)] fn main() { `fn fun1(&self,…)->Type1 {…}` }
implement trait on type
#![allow(unused)] fn main() { `impl Trait1 for Type1 {…}` }
implement trait method
-
use default implementation—do nothing
-
override implementation
#![allow(unused)] fn main() { `fn fun1(&self,…)->Type1 {…}` }
use trait as parameter
-
shorthand
#![allow(unused)] fn main() { `pub fn fun1(para1: &impl Trait1) {…}` } -
trait bound syntax
pub fn fun1<T: Trait1>(para1: &T) {…}
multiple trait bound +
- shorthand
pub fn fun1(para1: &(impl Trait1 + Trait2)) {…} - trait bound syntax
pub fn fun1<T: Trait1 + Trait2>(para1: &T) {…}
where clause
#![allow(unused)] fn main() { fn fun1<T,U>(t: &T, u: &U)->Type1 where T: Trait1 + Trait2, U: Trait3 + Trait4 {…} }
return type implement trait
#![allow(unused)] fn main() { `fn fun1(…)->impl Trait1 {…}` }
closure
anonymous function stored as variable that can capture its environment
#![allow(unused)] fn main() { `let closure1 = |var1,…| {return_value};` }
implement FnOnce trait
- more overhead than function
- automatically detect and decide type and cannot have multiple set of them
type annotation
|var1: type1,…| -> return_type {return_value};
storing closure
#![allow(unused)] fn main() { struct Store1<T> where T: Fn(type_for_var1,…) -> return_type, { attr1: T, … } }
- use a
Option<…> - use a hashmap
capture environment
-
borrow by default implement
Fntrait, mutable as needed implementFnMuttrait -
adopt ownership using
move#![allow(unused)] fn main() { `move |var1,…| {return_value}` }
R lang
naming
character allowed
letter, ., _
- cannot start with
_ - cannot start with
..
basic syntax
command separation
; or \n
comment
# last to the end of line
assignment
=
assignee <- assigner
assigner -> assignee
function
execute from .R file
source("filename.R")
manipulate data storage
show all object
objects()
remove object
rm(obj1,obj2,…)
store to disk
choose y when quit q()
stored as .RData
data structure
vector
c(ele1,ele2,…)
can also take vector as element, will expand
package managing
install package
install.packages("package_name")
- install multiple packages
use a vectorinstall.packages(c("package1","package2",…))
Shell
switch user to root and do
sudo
file & directory
print working directory
pwd
list file in path
ls [path]
change working directory to path, by default to ~
cd [path]
go up one directory
cd ..
go back to the last directory
cd -
copy one file to a given directory [and name it as instructed (the new name cannot be a local folder’s name, or it will just copy it there)]
cp <original file path> <new copy’s parent folder path>[/<new copy’s name>]
copy recursively one folder to a given directory
if the new directory does not exist,
the command will create it
cp -r <original folder path> <new copy’s parent folder path>
remove one file
rm <file path>
remove recursively one folder
rm -r <folder path>
remove one empty folder
rmdir <folder path>
make directory
mkdir
run the file
./<file name>
system information
display [human-readable (i.e., in MB, GB, etc.)] file system disk space usage
df [-h]
disk usage for this directory
du [path]
free and used memory in the system [in megabytes]
free [-m]
table of processes
top
print all system information: name, kernel, etc.
uname -a
print version information for the linux release
lsb_release -a
user
add a new user
adduser <new user’s name>
assign password to the user
passwd <user name>
manual
manual for the command
man <command>
introduction to linux command-line
man intro
search in manual what is <string>
whatis -r <string>
history
show command you input with numbers before them
history
Ctrl + R
search for command you input
cursor navigation
Ctrl + A/ Home
move cursor to start of line
Ctrl + E/ End
move cursor to end of line
Ctrl + B
move cursor to beginning of word
Ctrl + K
delete to the end of line
Ctrl + U
delete to start of line
Ctrl + W
delete word
Alt + B
go back one word
Alt + F
go forward one word
Alt + C
capitalize the letter and move cursor to end of word
Server
NFS
enable nfs
systemctl enable nfs-server
add directory to export:
edit etc/exports
directory_to_export ip_to_allow(rw,insecure)
export all specified directory
sudo exportfs -arv
mount on macOS
sudo mount -t nfs -v source target
automatically mount on macOS
-
open
/etc/fstabwithsudo vifs -
add into the file:
source /System/Volumes/Data/../Data/Volumes/target_name nfs rw,nolockd,resvport,hard,bg,intr,tcp,nfc,rsize=65536,wsize=65536-
for pre-Catalina, it should be
source /../Volumes/target_name nfs rw,nolockd,resvport,hard,bg,intr,tcp,nfc,rsize=65536,wsize=65536
-
SSH
kitty ssh
kitty +kitten ssh …
port forwarding
ssh -N -L 8080:127.0.0.1:8080 username@host
rsync
general usage
-P give a progress bar
rsync -P source destination
copy file from ssh server to client
rsync -P username@host:dir local_dir
copy file from client to ssh server
rsync -P local_dir username@host:dir
Text Editor
- Vim
- movement
- change
- count
- visual mode
- undo and redo
- fold
- spelling
- quit
- write as root
Vim
movement
arrow equivalent
↑
← h j k l →
↓
by word
to start of word
<–b– ○ –w–>
word word word
to end of word
ㅤㅤ<–ge–○ –e–>
word word word
by WORD
same as by word but capitalize the last letter
a WORD contains any consecutive non-whitespace character
search
search character
type a character in replace of w below
move to result
○–fw–>
word word
move to left of result
○–tw–>
word sword
backward
capitalize the letter
search expression
/…+entersearch forward?…+entersearch backward
repeat
nnext matchNlast match
expression
- exact
- regex
end of line
the end character
<–0– ○ –$–>
ㅤㅤlineㅤㅤ
the end non-whitespace character
ㅤㅤ<–^–– ○ ––g_–>
ㅤㅤnot whitespaceㅤㅤ
by chunk
by paragraph
paragraph 1
stuff
<–––– { ––––-+
paragraph 2 ○
more stuff |
<–––– } ––––-+
paragraph 3
by page
half page
- up
^u - down
^d
whole page
- up
^b - down
^f
to some position in this page
- Move to top of screen
H - Move to middle of screen
M - Move to bottom of screen
L - Top current line
zt - Center current line
zz - Bottom current line
zb
to past position
- go back to the previous jump position
'' - go to mark
letter:`+letter - go to top of last visual selection '`<'
- go to bottom of last visual selection '`>'
- go to top of last yanked '`['
- go to bottom of last yanked '`]'
- go to last change
g; - go to previous change in change history
g,
change
- delete current character and switch to insert mode
s - delete current line and switch to insert mode
S - delete current word and switch to insert mode
ciw - increase (decrease) line indent
>(<) - automatically indent line
= - change to uppercase/ lowercase
gU(gu) - toggle case
~
count
number + keys is the same as pressing keys for number times
go to line
number + G
or
number + gg
: + number
visual mode
visual mode navigation
- select whole paragraph
vip - select all inside quotes
vi"(not only quotes, others are similar) - select all inside tags
vit - select all and including quotes
va"(not only quotes, others are similar)
undo and redo
- undo
u - redo
^r - undo a line
U
fold
- toggle all fold
zi - toggle current fold
za
spelling
- spelling suggestions for current word
z= - add spelling of current word to dictionary
zg - remove spelling of current word to dictionary
zw
quit
- save all and quit
ZZ
write as root
:w !sudo tee %
StevenHe Public License
Version 1.0.2, 25 April 2022
Copyright (c) 2022 Sichang He (Steven) All rights reserved.
Basic Term
THIS LICENSE SHALL BE INCLUDED IN ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE.
Terms and Conditions
-
Definition of "Commercial Use"
Any activities that involve, directly or indirectly, the subject of the activity gaining financial benefits or any benefits in any other form that have the same effects as financial benefits, shall be considered "Commercial Use". "Commercial Use" includes but is not limited to:
Directly selling anything for benefits, including but not limited to financial payment, gifts, partnerships, and/or services.
Use to endorse or promote activities that involve benefits or objects related to such activities, including but not limited to endorsing or promoting commercial activities, commercial products, payed services, and/or brands.
-
Definition of "Non-commercial Use"
"Non-commercial Use" shall be considered the opposite of "Commercial Use". "Non-commercial Use" does not involve any financial benefits or any benefits in any other form that have the same effects as financial benefits to the subject of the activities. "Non-commercial Use" includes but is not limited to:
Use for any personal purpose, including learning, or solving personal problems.
Use for free and open-source software licensed under a license approved by the Open Source Initiative https://opensource.org.
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), for Non-commercial Use, to deal with this software without restriction, including without limitation the rights to use, copy, modify, merge, publish, and/or distribute copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that they follow the Basic Term.
-
Any use of the Software for "Commercial use" is subject to copyright laws. Please contact the author sichang.he@dukekunshan.edu.cn for permissions.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.